package com.itheima.mp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mp.domain.po.User;
import com.itheima.mp.mapper.UserMapperMp;
import com.itheima.mp.service.IUserService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapperMp, User> implements IUserService {

    @Override
    public List<User> queryUserListByMp(String name,
                                        Integer status,
                                        Integer minBalance,
                                        Integer maxBalance) {

        if ("zhilin".equals(name)) {
            System.out.println("1");
        } else if("chenkuan".equals(name)) {
            System.out.println("2");
        }

        return lambdaQuery()
                .like(null != name, User::getUsername, name)
                .eq(null != status, User::getStatus, status)
                .between(null != minBalance && null != maxBalance, User::getBalance, minBalance, maxBalance)
                .list();

    }

    @Override
    public void batchSave() {
        // 1-准备数据
        List<User> userList = initData();

        // 批量新增
        saveBatch(userList);
    }

    private List<User> initData() {

        List<User> userList = new ArrayList<>();

        for (int i = 0; i < 1000; i++) {
            User user = new User();
            user.setUsername(i + "-测试用户");
            user.setPassword(String.valueOf(i));
            user.setBalance(100);
            user.setInfo("测试数据");

            userList.add(user);
        }
        return userList;
    }
}
